package com.tingyuge.base.thread.concurrent1;

import java.util.Random;

/**
 * Created by xiaodao
 * date: 2019/11/26
 */
public class MyTest1 {

    public static void main(String[] args) {
        MyObjectWait myObject = new MyObjectWait();
        new Thread(()->{
            for (int i = 0; i < 30; i++) {
                try {
                    Thread.sleep(new Random().nextInt(1000));
                    myObject.add();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(()->{
            for (int i = 0; i < 30; i++) {
                try {
                    Thread.sleep(new Random().nextInt(1000));
                    myObject.add();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(()->{
            for (int i = 0; i < 30; i++) {
                try {
                    Thread.sleep(new Random().nextInt(1000));
                    myObject.sub();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(()->{
            for (int i = 0; i < 30; i++) {
                try {
                    Thread.sleep(new Random().nextInt(1000));
                    myObject.sub();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

}
